package com.education.expenses.entity;


import org.hibernate.annotations.ForeignKey;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * User: Егор
 * Date: 03.08.12
 * Time: 12:51
 */
@Entity
@Table(name = "report")
public class Report extends BaseEntity {

    @Column(name = "date_report")
    private Date dateReport;

    @ManyToOne(fetch = FetchType.LAZY)
    @ForeignKey(name = "FK_USER_REPORTS")
    @JoinColumn(name = "user_id")
    private User user;

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY, mappedBy = "report")
    private Set<Receipt> receipts;

    @Column(name = "report_status")
    @Enumerated(EnumType.STRING)
    private ReportStatus reportStatus;

    private Long meals;

    private Long lodging;

    private Long personal;

    private Long transportation;

    private Long misc;

    public Report(){}

    public Report(Date dateReport){
        this.dateReport = dateReport;
    }

    public void updateReport(Receipt receipt){
        meals += receipt.getMeals();
        lodging += receipt.getLodging();
        personal += receipt.getPersonal();
        transportation += receipt.getTransportation();
        misc += receipt.getMisc();
    }

    public Long getMeals() {
        return meals;
    }

    public void setMeals(Long meals) {
        this.meals = meals;
    }

    public Long getLodging() {
        return lodging;
    }

    public void setLodging(Long lodging) {
        this.lodging = lodging;
    }

    public Long getPersonal() {
        return personal;
    }

    public void setPersonal(Long personal) {
        this.personal = personal;
    }

    public Long getTransportation() {
        return transportation;
    }

    public void setTransportation(Long transportation) {
        this.transportation = transportation;
    }

    public Long getMisc() {
        return misc;
    }

    public void setMisc(Long misc) {
        this.misc = misc;
    }

    public ReportStatus getReportStatus() {
        return reportStatus;
    }

    public void setReportStatus(ReportStatus reportStatus) {
        this.reportStatus = reportStatus;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Set<Receipt> getReceipts() {
        return receipts;
    }

    public void setReceipts(Set<Receipt> receipts) {
        this.receipts = receipts;
    }

    public Date getDateReport() {
        return dateReport;
    }

    public void setDateReport(Date dateReport) {
        this.dateReport = dateReport;
    }
}
